<?php
/**
 * 教师信息展示
 */
include "../util/DBUtil.php";

//获取搜索框值
$key = $_GET['key'];
$key_type = $_GET['key_type'];

$db = new DBUtil();
$result = array();
if ($key == "") {//不进行搜索操作
    $sql = "select tb_teacher.*,tb_grade.grade from tb_teacher,tb_grade where tb_teacher.grade_id = tb_grade.id ";
    $result = $db->query($sql);//存放结果集
} else {//查询
    if ($key_type == 0) {//编号查询
        $sql = "select tb_teacher.*,tb_grade.grade from tb_teacher,tb_grade where tb_teacher.grade_id = tb_grade.id and tb_teacher.teacher_no like ? ";
    }elseif ($key_type==1){//名字查询
        $sql = "select tb_teacher.*,tb_grade.grade from tb_teacher,tb_grade where tb_teacher.grade_id = tb_grade.id and tb_teacher.name like ? ";
    }elseif ($key_type==2){//班级查询
        $sql = "select tb_teacher.*,tb_grade.grade from tb_teacher,tb_grade where tb_teacher.grade_id = tb_grade.id and tb_grade.grade like ? ";
    }
//    echo $sql;
    $params = array('%'.$key.'%');
    $result = $db->query($sql,$params);//存放结果集
}

?>

<link rel="stylesheet" href="../css/bootstrap.min.css">
<table class="table table-striped">
    <tr>
        <th>ID</th>
        <th>编号</th>
        <th>名字</th>
        <th>所管理班级</th>
        <th>密码</th>
        <th>编辑</th>
    </tr>
    <?php
    foreach ($result as $item){
        ?>
        <tr>
            <td><?php echo $item['id']?></td>
            <td><?php echo $item['teacher_no']?></td>
            <td><?php echo $item['name']?></td>
            <td><?php echo $item['grade']?></td>
            <td><?php echo $item['password']?></td>
            <td>
                <a href="../view/edit_teacher.php?id=<?php echo $item['id']?>&flag=0" target="info">
                    <button class="btn btn-primary">修改</button>
                </a>
                <a href="../view/edit_teacher.php?id=<?php echo $item['id']?>&flag=1" target="info">
                    <button onclick="alert('是否删除？')" class="btn btn-danger">删除</button>
                </a>
            </td>
        </tr>
        <?php
    }
    ?>
</table>


